package com.ywq.app.web.mvc.member;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.ywq.app.bean.ImageWeb;
import com.ywq.app.biz.ArtFindBiz;
import com.ywq.app.biz.ArtMadeBiz;
import com.ywq.app.biz.ArtPicBiz;
import com.ywq.app.biz.ImageBiz;
import com.ywq.app.biz.MailBiz;
import com.ywq.app.biz.MemberBiz;
import com.ywq.app.domain.ArtArtist;
import com.ywq.app.domain.ArtBack;
import com.ywq.app.domain.ArtClass;
import com.ywq.app.domain.ArtMade;
import com.ywq.app.domain.ArtMadeTalk;
import com.ywq.app.domain.ArtOrders;
import com.ywq.app.domain.ArtPic;
import com.ywq.app.domain.ArtProcessLog;
import com.ywq.app.domain.Member;
import com.ywq.app.domain.MemberAddress;
import com.ywq.app.domain.MemberBank;
import com.ywq.app.domain.MemberHas;
import com.ywq.app.domain.MemberHobby;
import com.ywq.app.domain.MemberSecurity;
import com.ywq.app.domain.OnLineUserListener;
import com.ywq.app.web.mvc.test.CommonController;
import com.ywq.common.constant.Constant;
import com.ywq.common.exception.AppBusinessException;
import com.ywq.common.page.PageModel;
import com.ywq.common.util.Common;
import com.ywq.common.util.Encode;


@Controller
public class MemberController {
	private final static Logger logger = LoggerFactory.getLogger(MemberController.class);
	@Autowired
	private MemberBiz memberBiz;
	@Autowired
	private ArtMadeBiz artMadeBiz;
	@Autowired
	private ImageBiz imageBiz;
	@Autowired
	private ArtPicBiz artPicBiz;
	@Autowired
	private ArtFindBiz artFindBiz;
	/*@Autowired
	private ImageBiz imageBiz;
	@Autowired
	private MailBiz mailBiz;
	/*@Autowired
	private WeiboBiz weiboBiz;*/
	@Autowired
	private MailBiz mailBiz;
	/**
	 * 登录页面
	 * 
	 * @param request
	 * @param memberOutAccount
	 * @return
	 * @throws AppBusinessException
	 */
	@RequestMapping(value = "/login.htm")
	public String enterLogin(HttpServletRequest request)
			throws AppBusinessException {
		String registerReferer = request.getHeader("referer");
		request.getSession().setAttribute("registerReferer", registerReferer);
		String loginReferer = request.getHeader("referer");
		request.getSession().setAttribute("loginReferer", loginReferer);
		// request.setAttribute("memberOutAccount", memberOutAccount);
		return "login";
	}

	/**
	 * 登录
	 * 
	 * @author zhang
	 * @param request
	 * @param response
	 * @return
	 * @throws IOException
	 */
	@RequestMapping(value = "/loginOn.htm")
	public String login(HttpServletRequest request, HttpServletResponse response, String hisUrl) {
		try {

			String result = memberBiz.login(request, response);
			if ("dailylogin".equals(result)) {
					// 来源
					String registerReferer = (String) request.getSession().getAttribute("registerReferer");
					if (Common.notEmptyStr(registerReferer)) {
						response.sendRedirect(registerReferer);
					} else {
						//pw.print("member.htm");
						response.sendRedirect("/member.htm");
					}
			} else if ("noRegister".equals(result)) {
				request.setAttribute("loginError","登录失败，用户名或密码输入错误或用户名不存在请马上注册");
				return "login";
			} 
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("[/loginOn.htm] fail.", e);
			}
		}
		return null;
	}

	/**
	 * 退出
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/logout.htm", method = RequestMethod.GET)
	public String logout(HttpServletRequest request,
			HttpServletResponse response) {
		try {
			request.getSession(true).removeAttribute("onlineUser");
			response.sendRedirect("/welcome.htm");
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("[/logout.htm] fail.",e);
			}
		}
		return null;
	}
	@RequestMapping(value = "/logoutAll.htm", method = RequestMethod.POST)
	public String logoutAll(HttpServletRequest request,
			HttpServletResponse response) {
		try {
			PrintWriter out = response.getWriter();
            response.setContentType("text/html;charset=UTF-8");
			request.getSession(true).removeAttribute("onlineUser");
			request.getSession(true).removeAttribute("out");
			out.print("true");
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("[/logout.htm] fail.",e);
			}
		}
		return null;
	}
	/**
	 * 注册页面
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws IOException
	 */
	@RequestMapping(value = "/register.htm")
	public String register(HttpServletRequest request,
			HttpServletResponse response) throws IOException {
		String registerReferer = request.getHeader("referer");
		request.getSession().setAttribute("registerReferer", registerReferer);
		return "register";
	}
	/**
	 * // 注册
	 * 
	 * @param member
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/registerOn.htm", method = RequestMethod.POST)
	public String registerOn(String vCode, Member member,
			HttpServletRequest request, HttpServletResponse response,
			String outUserReg) {

		response.setContentType("text/html;charset=UTF-8");
		PrintWriter pw = null;
		try {
			String sessionCode = String.valueOf(request.getSession().getAttribute("code"));
			String outName = String.valueOf(request.getSession().getAttribute("outName"));
			String outId = String.valueOf(request.getSession().getAttribute("outId"));
			String qqfigureurl = String.valueOf(request.getSession().getAttribute("qqfigureurl"));
			
			System.out.println(outName+"____________________________________"+qqfigureurl+"_______________________________________"+outId);
			pw = response.getWriter();
			if(Common.notEmptyStr(outName)){
				member.setNickname(outName);
				member.setOutId(outId);
				member.setOutName(outName);
				member.setAvatar(qqfigureurl);
				request.getSession().removeAttribute("outName");
				request.getSession().removeAttribute("outId");
			}
			if (Common.notEmptyStr(vCode) && !vCode.equals(sessionCode)) {
				pw.print("codeError");
				return null;
			} else {
				// 注册信息
				// 发送验证邮箱
				//String path = request.getContextPath();
				String emailPath = "http://befamousstore.com/";
				member.setRegisterIP(request.getRemoteAddr());
				member.setLoginIP(request.getRemoteAddr());
				// 注册
				Member memeberSession = memberBiz.register(emailPath, member);
				request.getSession(true).setAttribute("onlineUser",
						new OnLineUserListener(memeberSession));
				request.getSession().removeAttribute("accessUser");
				// 来源
				String registerReferer = (String) request.getSession().getAttribute("registerReferer");
				if (Common.notEmptyStr(registerReferer)) {
					response.sendRedirect(registerReferer);
				} else {
					//pw.print("member.htm");
					response.sendRedirect("/member.htm");
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			pw.print("error");
		}
		return null;
	}

	/**
	 * 邮箱验证
	 * 
	 * @param request
	 * @param response
	 * @throws AppBusinessException
	 */
	@RequestMapping(value = "/checkEmail.htm")
	public void checkEmail(HttpServletRequest request,
			HttpServletResponse response) throws AppBusinessException {
		String email = request.getParameter("email");
		if (Common.empty(email))
			return;
		response.setContentType("text/html;charset=UTF-8");
		PrintWriter pw = null;
		try {
			pw = response.getWriter();
			Member m = memberBiz.getMemberEmail(email);
			if (m != null) {
				pw.print(false);
			} else {
				pw.print(true);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 昵称验证
	 * 
	 * @param request
	 * @param response
	 * @param nickname
	 * @throws AppBusinessException
	 */
	@RequestMapping(value = "/checkNickname.htm")
	public void ckNickname(HttpServletRequest request,
			HttpServletResponse response, String nickname)
			throws AppBusinessException {
		if (Common.empty(nickname))
			return;
		response.setContentType("text/html;charset=UTF-8");
		PrintWriter pw = null;
		try {
			pw = response.getWriter();
			Member m = memberBiz.getMemberNickName(nickname);
			if (Common.empty(m)) {
				pw.print(true);
			} else {
				pw.print(false);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	//阅读
	@RequestMapping(value = "/read.htm")
	public String read(HttpServletRequest request,
			HttpServletResponse response) throws IOException {
		return "read";
	}
	/**
	 * 会员主页()
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws IOException
	 */
	@RequestMapping(value = "/member.htm")
	public String member(HttpServletRequest request,
			HttpServletResponse response) throws IOException {
		OnLineUserListener onLineUserListener = (OnLineUserListener) request
				.getSession().getAttribute("onlineUser");
		if (onLineUserListener != null) {
			try {

				Member member = memberBiz.getMemberById(onLineUserListener.getMember().getId());
				try {
					//购买订单3个
					Map<String ,Object> bMap =new HashMap<String,Object> ();
					bMap.put("pageSize", 3);
					bMap.put("startId", 0);
					bMap.put("type", "find");
					bMap.put("memberId", member.getId());
					List<ArtOrders> bOrdersList =memberBiz.getOrdersListByMemberId(bMap);
					//拍卖订单4个
					Map<String ,Object> aMap =new HashMap<String,Object> ();
					aMap.put("pageSize", 4);
					aMap.put("startId", 0);
					aMap.put("type", "auction");
					aMap.put("memberId", member.getId());
					List<ArtOrders> aOrdersList =memberBiz.getOrdersListByMemberId(aMap);
					request.setAttribute("bOrdersList", bOrdersList);
					request.setAttribute("aOrdersList", aOrdersList);
					//近30天的订单数
					int countThity =memberBiz.getCountThity(member.getId());
					request.setAttribute("countThity", countThity);
				} catch (Exception e) {
					e.printStackTrace();
				}
				request.setAttribute("member", member);
				
			} catch (AppBusinessException e) {
				e.printStackTrace();
			}
			return "artOne/member/member";
		} else {
			response.sendRedirect("/welcome.htm");
			return null;
		}

	}
	//订单列表
	@RequestMapping(value = "/mOrders.htm")
	public String mOrder(Integer page,HttpServletRequest request,
			HttpServletResponse response) throws IOException {
		OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser");
		if (page == null) {
			page = 1;
		}
		if (onLineUserListener != null) {
			try {
				Member member = memberBiz.getMemberById(onLineUserListener.getMember().getId());
				PageModel pageOrderAuction = memberBiz.getOrdersById(page,member.getId(),"auction");
				PageModel pageOrderFind = memberBiz.getOrdersById(page,member.getId(),"find");
				request.setAttribute("pageOrderAuction", pageOrderAuction);
				request.setAttribute("pageOrderFind", pageOrderFind);
			} catch (AppBusinessException e) {
				e.printStackTrace();
			}
			return "artOne/member/mOrder";
		} else {
			response.sendRedirect("/welcome.htm");
			return null;
		}

	}
	//活动
	@RequestMapping(value = "/mActivity.htm")
	public String mActivity(Integer page,HttpServletRequest request,
			HttpServletResponse response) throws IOException {
		OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser");
		if (page == null) {
			page = 1;
		}
		if (onLineUserListener != null) {
			try {
				Member member = memberBiz.getMemberById(onLineUserListener.getMember().getId());
				PageModel pageActivity = memberBiz.getActivityById(page,member.getId());
				request.setAttribute("pageActivity", pageActivity);
			} catch (AppBusinessException e) {
				e.printStackTrace();
			}
			return "artOne/member/mActivity";
		} else {
			response.sendRedirect("/welcome.htm");
			return null;
		}

	}
	//artHas
	@RequestMapping(value = "/artHas.htm", method = RequestMethod.GET)
	public String artHas(String picId,String owner,String type,HttpServletRequest request,HttpServletResponse response) throws IOException {
		response.setContentType("text/html; charset=UTF-8");
		PrintWriter pw = null;
		try {
			OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser");
			if(onLineUserListener.getMember()!=null){
				//
				Map<String, Object> map = new HashMap<String, Object>();
				map.put("ownerId", picId);
				map.put("memberId", onLineUserListener.getMember().getId());
				map.put("owner", owner);
				map.put("type", type);
				List<MemberHas> list = memberBiz.getHasList(map);
				
				if (list != null && list.size() > 0) {
					pw = response.getWriter();
					pw.print("alreadyLove");
				} else {
					MemberHas memberHas =new MemberHas();
					memberHas.setMemberId(onLineUserListener.getMember().getId());
					memberHas.setOwnerId(picId);
					memberHas.setOwner(owner); //look love keep 
					memberHas.setType(type); //发现、拍卖、展览馆
					memberBiz.insertMemberHas(memberHas);
					//增加作品 look love keep 数
					ArtPic artPicOld =artPicBiz.getArtPic(picId);
					ArtPic artPic =new ArtPic();
					artPic.setIdentifier(picId);
					artPic.setLoveAmount(artPicOld.getLoveAmount()+1);
					artPicBiz.updatePicViewAmount(artPic);
					pw = response.getWriter();
					pw.print("loveSuccess");
				}
			}else{
				pw = response.getWriter();
				pw.print("error");
			}
		} catch (Exception e) {
			pw = response.getWriter();
			pw.print("error");
			if (logger.isErrorEnabled()) {
				logger.error("auction failure.", e);
			}
		}
		return null;
		}
		//取消Has
	@RequestMapping(value = "/noArtHas.htm", method = RequestMethod.POST)
	public String noArtHas(String hasId,HttpServletRequest request,HttpServletResponse response) throws IOException {
		response.setContentType("text/html; charset=UTF-8");
		PrintWriter pw = null;
		try {
			OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser");
			if(onLineUserListener.getMember()!=null){
				memberBiz.deleteMemberHas(hasId);
				pw = response.getWriter();
				pw.print("success");
			}else{
				pw = response.getWriter();
				pw.print("error");
			}
		} catch (Exception e) {
			pw = response.getWriter();
			pw.print("error");
			if (logger.isErrorEnabled()) {
				logger.error("auction failure.", e);
			}
		}
		return null;
		}
	//不参加活动
	@RequestMapping(value = "/noJoin.htm", method = RequestMethod.POST)
	public String noJoin(String acId,HttpServletRequest request,HttpServletResponse response) throws IOException {
		response.setContentType("text/html; charset=UTF-8");
		PrintWriter pw = null;
		try {
			OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser");
			if(!Common.empty(onLineUserListener.getMember())){
				//memberBiz.deleteMemberHas(hasId);
				memberBiz.noJoinActivity(acId,onLineUserListener.getMember().getId());
				pw = response.getWriter();
				pw.print("success");
			}else{
				pw = response.getWriter();
				pw.print("error");
			}
		} catch (Exception e) {
			pw = response.getWriter();
			pw.print("error");
			if (logger.isErrorEnabled()) {
				logger.error("auction failure.", e);
			}
		}
		return null;
		}
	//会员信息
	@RequestMapping(value = "/memberInfo.htm")
	public String mInfo(HttpServletRequest request,HttpServletResponse response) throws IOException {
		OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser");
		
		if (onLineUserListener != null) {
			try {
				Member member = memberBiz.getMemberById(onLineUserListener.getMember().getId());
				//PageModel pageActivity = memberBiz.getActivityById(page,member.getId());
				request.setAttribute("member", member);
			} catch (AppBusinessException e) {
				e.printStackTrace();
			}
			return "artOne/member/mInfo";
		} else {
			response.sendRedirect("/welcome.htm");
			return null;
		}

	}
	//保存详情资料
	@RequestMapping(value = "/saveInfo.htm", method = RequestMethod.POST)
	public String saveInfo(Member member,HttpServletRequest request,HttpServletResponse response) throws IOException {
		response.setContentType("text/html; charset=UTF-8");
		PrintWriter pw = null;
		try {
			OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser");
			if(!Common.empty(onLineUserListener.getMember())){
				member.setId(onLineUserListener.getMember().getId());
				memberBiz.update(member);
				pw = response.getWriter();
				pw.print("success");
			}else{
				pw = response.getWriter();
				pw.print("error");
			}
		} catch (Exception e) {
			pw = response.getWriter();
			pw.print("error");
			if (logger.isErrorEnabled()) {
				logger.error("auction failure.", e);
			}
		}
		return null;
		}
	//验证密码
	@RequestMapping(value = "/checkPassword.htm", method = RequestMethod.GET)
	public void checkPassword(HttpServletRequest request,
			HttpServletResponse response) throws AppBusinessException {
		String password = request.getParameter("oldPassWord");
		OnLineUserListener onLineUserListener = (OnLineUserListener) request
				.getSession().getAttribute("onlineUser");
		if (Common.empty(password))
			return;
		response.setContentType("text/html;charset=UTF-8");
		PrintWriter pw = null;
		try {
			pw = response.getWriter();
			Member member = memberBiz.getMemberByNick(password,
					(onLineUserListener.getMember().getNickname()));
			boolean pswNotExist = false;
			if (member != null) {
				pswNotExist = true;
			}
			pw.print(pswNotExist);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	/**
	 * // 修改密码
	 * 
	 * @param request
	 * @param response
	 * @throws AppBusinessException
	 */
	@RequestMapping(value = "/ModifyPw.htm")
	public void ModifyPw(String newPassWord, HttpServletRequest request,
			HttpServletResponse response) throws AppBusinessException {
		try {
			response.setContentType("text/html; charset=UTF-8");
			PrintWriter out = response.getWriter(); 
			OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser"); 
			Member m = onLineUserListener.getMember();
			if (Common.notEmptyStr(m.getId())
					&& Common.notEmptyStr(newPassWord) && m != null
					&& m.getEnabled()) {
				Member member = new Member();
				member.setId(m.getId());
				member.setPassword(Common.md5(Common.md5(newPassWord)));
				memberBiz.update(member);
				out.print("success");
			} else {
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

	}
	//银行账号
	@RequestMapping(value = "/mBank.htm")
	public String mBank(HttpServletRequest request,HttpServletResponse response) throws IOException {
		OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser");
		
		if (onLineUserListener != null) {
			try {
				Member member = memberBiz.getMemberById(onLineUserListener.getMember().getId());
				List<MemberBank> bankList =memberBiz.getBankLiatByMemberId(onLineUserListener.getMember().getId());
				//PageModel pageActivity = memberBiz.getActivityById(page,member.getId());
				request.setAttribute("member", member);
				request.setAttribute("bankList", bankList);
			} catch (AppBusinessException e) {
				e.printStackTrace();
			}
			return "artOne/member/mBank";
		} else {
			response.sendRedirect("/welcome.htm");
			return null;
		}

	}
	//保存账号
	@RequestMapping(value = "/saveBank.htm")
	public void saveBank(MemberBank memberBank,HttpServletRequest request,HttpServletResponse response) throws AppBusinessException {
		try {
			response.setContentType("text/html; charset=UTF-8");
			PrintWriter out = response.getWriter(); 
			OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser"); 
			Member m = onLineUserListener.getMember();
			if (m!=null){
				memberBank.setMemberId(m.getId());
					memberBiz.noAllBankDefault(m.getId());
					memberBiz.insertMemberBank(memberBank);
				out.print("success");
				} else {
					out.print("error");
				}
		} catch (Exception e) {
			e.printStackTrace();
		}

	}
	@RequestMapping(value = "/sendEmail.htm")
	public void sendEmail(HttpServletRequest request,HttpServletResponse response) throws AppBusinessException {
		try {
			response.setContentType("text/html; charset=UTF-8");
			PrintWriter out = response.getWriter(); 
			OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser"); 
			Member m = onLineUserListener.getMember();
			if (m!=null){
				if(m.getEmail()!=null && m.getEmail()!=""){
					String emailPath = "http://mkhg.v084.10000net.cn/";
					mailBiz.sendEmail(emailPath, m,null,null);
				}else{
					out.print("noemail");
				}
				out.print("success");
				} else {
					out.print("error");
				}
		} catch (Exception e) {
			e.printStackTrace();
		}

	}
	
	//删除银行账号
	@RequestMapping(value = "/deleteBankId.htm")
	public void deleteBankId(String id,HttpServletRequest request,HttpServletResponse response) throws AppBusinessException {
		try {
			response.setContentType("text/html; charset=UTF-8");
			PrintWriter out = response.getWriter(); 
			OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser"); 
			Member m = onLineUserListener.getMember();
			if (m!=null){
					memberBiz.deleteMemberBank(id);
				out.print("success");
				} else {
					out.print("error");
				}
		} catch (Exception e) {
			e.printStackTrace();
		}

	}
	//我的喜好
	@RequestMapping(value = "/mHobby.htm")
	public String mHobby(HttpServletRequest request,HttpServletResponse response) throws IOException {
		OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser");
		
		if (onLineUserListener != null) {
			try {
				Member member = memberBiz.getMemberById(onLineUserListener.getMember().getId());
				List<ArtClass> deptList=artPicBiz.getChildById("0", Constant.PIC_DEPARTMENT_CLASS);
				List<ArtClass> sportList=artPicBiz.getChildById("0", Constant.PIC_SPORT_CLASS);
				List<ArtClass> themeList=artPicBiz.getChildById("0", Constant.PIC_THEME_CLASS);
				List<ArtClass> mediaList=artPicBiz.getChildById("0", Constant.PIC_MEDIA_CLASS);
				List<MemberHobby> hobbyList =memberBiz.getHobbyListByMemberId(member.getId());
				request.setAttribute("hobbyList", hobbyList);
				request.setAttribute("member", member);
				request.setAttribute("deptList", deptList);
				request.setAttribute("sportList", sportList);
				request.setAttribute("themeList", themeList);
				request.setAttribute("mediaList", mediaList);
			} catch (AppBusinessException e) {
				e.printStackTrace();
			}
			return "artOne/member/mHobby";
		} else {
			response.sendRedirect("/welcome.htm");
			return null;
		}

	}
	//收货地址
	@RequestMapping(value = "/mAddress.htm")
	public String mAddress(HttpServletRequest request,HttpServletResponse response) throws IOException {
		OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser");
		
		if (onLineUserListener != null) {
			try {
				Member member = memberBiz.getMemberById(onLineUserListener.getMember().getId());
				List<MemberAddress> addressList =memberBiz.getAddressListByMemberId(onLineUserListener.getMember().getId());
				request.setAttribute("member", member);
				request.setAttribute("addressList", addressList);
			} catch (AppBusinessException e) {
				e.printStackTrace();
			}
			return "artOne/member/mAddress";
		} else {
			response.sendRedirect("/welcome.htm");
			return null;
		}

	}
	//保存地址
	@RequestMapping(value = "/saveAddress.htm")
	public void saveAddress(MemberAddress memberAddress,HttpServletRequest request,HttpServletResponse response) throws AppBusinessException {
		try {
			response.setContentType("text/html; charset=UTF-8");
			PrintWriter out = response.getWriter(); 
			OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser"); 
			Member m = onLineUserListener.getMember();
			if (m!=null){
					memberAddress.setMemberId(m.getId());
					memberBiz.insertMemberAddress(memberAddress);
				out.print("success");
				} else {
					out.print("error");
				}
		} catch (Exception e) {
			e.printStackTrace();
		}

	}
	//更新地址
	@RequestMapping(value = "/updateAddress.htm")
	public void updateAddress(MemberAddress memberAddress,HttpServletRequest request,HttpServletResponse response) throws AppBusinessException {
		try {
			response.setContentType("text/html; charset=UTF-8");
			PrintWriter out = response.getWriter(); 
			OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser"); 
			Member m = onLineUserListener.getMember();
			if (m!=null){
					memberAddress.setMemberId(m.getId());
					memberBiz.updateMemberAddress(memberAddress);
				out.print("success");
				} else {
					out.print("error");
				}
		} catch (Exception e) {
			e.printStackTrace();
		}

	}
	//选择地址
	@RequestMapping(value = "/addressTo.htm")
	public String addressTo(String oId,HttpServletRequest request,HttpServletResponse response) throws IOException {
		OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser");
		
		if (onLineUserListener != null) {
			try {
				Member member = memberBiz.getMemberById(onLineUserListener.getMember().getId());
				List<MemberAddress> addressList =memberBiz.getAddressListByMemberId(onLineUserListener.getMember().getId());
				request.setAttribute("member", member);
				ArtOrders order =memberBiz.getOrdersById(oId);
				request.setAttribute("addressList", addressList);
				request.setAttribute("myOrders", order);
			} catch (AppBusinessException e) {
				e.printStackTrace();
			}
			return "artOne/member/addressTo";
		} else {
			response.sendRedirect("/welcome.htm");
			return null;
		}

	}
	//修改地址页面
	@RequestMapping(value = "/mAddressUpdate.htm")
	public String mAddressUpdate(String aid,HttpServletRequest request,HttpServletResponse response) throws IOException {
		OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser");
		
		if (onLineUserListener != null) {
			try {
				Member member = memberBiz.getMemberById(onLineUserListener.getMember().getId());
				MemberAddress address =memberBiz.getAddressByaId(aid);
				request.setAttribute("member", member);
				request.setAttribute("list", address);
			} catch (AppBusinessException e) {
				e.printStackTrace();
			}
			return "artOne/member/mAddressUpdate";
		} else {
			response.sendRedirect("/welcome.htm");
			return null;
		}
	}
	//增加订单地址
	@RequestMapping(value = "/addOrderAddress.htm")
	public void addOrderAddress(String addId,String oId,HttpServletRequest request,HttpServletResponse response) throws AppBusinessException {
		try {
			response.setContentType("text/html; charset=UTF-8");
			PrintWriter out = response.getWriter(); 
			OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser"); 
			Member m = onLineUserListener.getMember();
				if (m!=null){
					MemberAddress artAddress =memberBiz.getAddressByaId(addId);
					Map<String, Object> map = new HashMap<String, Object>();
					//地址
					//map.put("remark", addId);
					map.put("addressName", artAddress.getAddressName());
					map.put("phone", artAddress.getPhone());
					map.put("telphone", artAddress.getTelphone());
					map.put("goodTime", artAddress.getGoodTime());
					map.put("province", artAddress.getProvince());
					map.put("city", artAddress.getCity());
					map.put("address", artAddress.getAddress());
					map.put("zipcode", artAddress.getZipcode());
					map.put("county", artAddress.getCounty());
					map.put("id", oId);
					memberBiz.updateOrders(map);
				out.print("success");
				} else {
					out.print("error");
				}
		} catch (Exception e) {
			e.printStackTrace();
		}

	}
	//订单详情
	@RequestMapping(value = "/orders.htm")
	public String Orders(String oId,HttpServletRequest request, HttpServletResponse response) throws IOException {
		OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser");
		if (onLineUserListener != null) {
			try {
				Member member = memberBiz.getMemberById(onLineUserListener.getMember().getId());
				ArtOrders order =memberBiz.getOrdersById(oId);
				//MemberAddress address =memberBiz.getAddressByaId(order.getRemark());
				//request.setAttribute("address", address);
				request.setAttribute("order", order);
				request.setAttribute("member", member);
			} catch (AppBusinessException e) {
				e.printStackTrace();
			}
			return "artOne/member/showOrder";
		} else {
			response.sendRedirect("/welcome.htm");
			return null;
		}

	}
	//退货
	@RequestMapping(value = "/goodsback.htm")
	public String goodsback(String oId,HttpServletRequest request, HttpServletResponse response) throws IOException {
		OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser");
		if (onLineUserListener != null) {
				request.setAttribute("orderId", oId);
			return "artOne/member/goodsback";
		} else {
			response.sendRedirect("/welcome.htm");
			return null;
		}

	}
	
	//定制列表
	@RequestMapping(value = "/mMade.htm")
	public String mMade(Integer page,HttpServletRequest request, HttpServletResponse response) throws IOException {
		OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser");
		if (onLineUserListener != null) {
			try {
				Member member = memberBiz.getMemberById(onLineUserListener.getMember().getId());
				if (page == null) {
					page = 1;
				}
				Map<String, Object> map = new HashMap<String, Object>();
				map.put("page", page);
				map.put("pagesize", 10);
				map.put("memberId", member.getId());
				PageModel pageModel = artMadeBiz.getMadeOrderList(map);
				request.setAttribute("pageModel", pageModel);
				request.setAttribute("member", member);
			} catch (AppBusinessException e) {
				e.printStackTrace();
			}
			return "artOne/member/mMade";
		} else {
			response.sendRedirect("/welcome.htm");
			return null;
		}

	}
	//定制详情
	@RequestMapping(value = "/talk.htm")
	public String mMade(String id,HttpServletRequest request, HttpServletResponse response) throws IOException {
		OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser");
		if (onLineUserListener != null) {
			try {
				Member member = memberBiz.getMemberById(onLineUserListener.getMember().getId());
				//对话三阶段
				//1
				List<ArtMadeTalk> talkListOne =artMadeBiz.getTalkListByMadeId(id,"01");
				//2
				List<ArtMadeTalk> talkListTow =artMadeBiz.getTalkListByMadeId(id,"02");
				//3
				List<ArtMadeTalk> talkListThird =artMadeBiz.getTalkListByMadeId(id,"03");
				//4
				List<ArtMadeTalk> talkListFour =artMadeBiz.getTalkListByMadeId(id,"04");
				//某一订单
				ArtMade artMade=artMadeBiz.getArtMadeById(id);
				request.setAttribute("artMade", artMade);
				request.setAttribute("talkListOne", talkListOne);
				request.setAttribute("talkListTow", talkListTow);
				request.setAttribute("talkListThird", talkListThird);
				request.setAttribute("talkListFour", talkListFour);
				request.setAttribute("member", member);
			} catch (AppBusinessException e) {
				e.printStackTrace();
			}
			return "artOne/artMade/madeTalk";
		} else {
			response.sendRedirect("/welcome.htm");
			return null;
		}

	}
	//定制提问
	@RequestMapping(value = "/askTalk.htm")
	public String askTalk(String id,HttpServletRequest request, HttpServletResponse response) throws IOException {
		OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser");
		if (onLineUserListener != null) {
			try {
				Member member = memberBiz.getMemberById(onLineUserListener.getMember().getId());
				//新建对话页面
				//某一订单
				ArtMade artMade=artMadeBiz.getArtMadeById(id);
				request.setAttribute("artMade", artMade);
				request.setAttribute("madeId", id);
				request.setAttribute("member", member);
			} catch (AppBusinessException e) {
				e.printStackTrace();
			}
			return "artOne/artMade/askTalk";
		} else {
			response.sendRedirect("/welcome.htm");
			return null;
		}

	}
	//增加会员talk
	@RequestMapping(value = "/addTalk.htm")
	public void addArtMadeTalk(ArtMadeTalk artMadeTalk,HttpServletRequest request,HttpServletResponse response) throws AppBusinessException {
		try {
			response.setContentType("text/html; charset=UTF-8");
			PrintWriter out = response.getWriter(); 
			OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser"); 
			Member m = onLineUserListener.getMember();
				if (m!=null){
					artMadeTalk.setMemberId(m.getId());
					artMadeTalk.setMemberType("member");
					ArtMade artMade=artMadeBiz.getArtMadeById(artMadeTalk.getMadeId());
					artMadeTalk.setMadeStage(artMade.getStage());
					artMadeBiz.insertArtMadeTalk(artMadeTalk);
				out.print("success");
				} else {
					out.print("error");
				}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	/**
	 * 上传图片
	 * @param request
	 * @param response
	 * @return
	 * @throws IOException
	 */
	@RequestMapping(value = "/uploadImg.htm")
	public String uploadImg(HttpServletRequest request,HttpServletResponse response) throws IOException {
		//System.out.print("111111111");
		response.setContentType("text/html; charset=UTF-8"); 
		response.setHeader("Cache-Control", "no-cache");
		PrintWriter pw = null; 
		try {
			String imageDir=getRootPath();
			ImageWeb imageWeb = imageBiz.uploadOneImg(request, Constant.IMAGE_PATH_ART,imageDir);
			pw = response.getWriter();
			pw.print(JSONObject.fromObject(imageWeb));
			//System.out.print(imageWeb);
		} catch (Exception e) {
			pw = response.getWriter();
			pw.print("error");
			if (logger.isErrorEnabled()) {
				logger.error("Add user failure.", e);
			}
		}
		return null;
	} 
	 public static String getRootPath(){   
	        //因为类名为"CommonController"，因此" CommonController.class"一定能找到   
	        String result = CommonController.class.getResource("CommonController.class").toString();   
	        int index = result.indexOf("WEB-INF");   
	        if(index == -1){   
	            index = result.indexOf("bin");   
	        }   
	        result = result.substring(0,index);   
	        if(result.startsWith("jar")){   
	            // 当class文件在jar文件中时，返回"jar:file:/F:/ ..."样的路径    
	            result = result.substring(10);   
	        }else if(result.startsWith("file")){   
	            // 当class文件在class文件中时，返回"file:/F:/ ..."样的路径    
	            result = result.substring(6);   
	        }   
	        if(result.endsWith("/"))result = result.substring(0,result.length()-1);//不包含最后的"/"   
	        return result;   
	    } 
	 
		//邮箱验证成功
		@RequestMapping(value = "/successValede.htm", method = RequestMethod.GET)
		public String successValede(String number, HttpServletRequest request, HttpServletResponse response) throws AppBusinessException {
			try {
				Member member = memberBiz.getMemberById(number);
				if (member == null) {
					return "v1/common/error";
				} else {
					
					if(!member.getIsActive()){
						member.setIsActive(true);
						memberBiz.update(member);
						request.getSession(true).setAttribute("onlineUser",new OnLineUserListener(member));
						request.setAttribute("member", member);
						response.sendRedirect("/member.htm");
						return null;
					}else{
						return "login";
					}
				}
			} catch (Exception e) {
				e.printStackTrace();
				try {
					response.sendRedirect("/welcome.htm");
				} catch (IOException e1) {
					e1.printStackTrace();
				}
				return null;
			}
		}
		 //检查是否登录
	    @RequestMapping(value = "/member/checklogin.htm")
	    public String checkMemberLogin(HttpServletRequest request, HttpServletResponse response) {
	    	OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser"); 
	        try {
	            PrintWriter out = response.getWriter();
	            response.setContentType("text/html;charset=UTF-8");
	            if (!Common.empty(onLineUserListener.getMember())) {
	                out.print("logged");
	            } else {
	                out.print("nologin");
	            }
	        } catch (Exception e) {
	            logger.error("[/member/checklogin.htm] fail");
	            e.printStackTrace();
	        }
	        return null;
	    }
	    //收藏
	    @RequestMapping(value = "/mHas.htm")
		public String mKeep(HttpServletRequest request,HttpServletResponse response) throws IOException {
			OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser");
			
			if (onLineUserListener != null) {
				try {
					//展览馆
					Member member = memberBiz.getMemberById(onLineUserListener.getMember().getId());
					Map<String, Object> map = new HashMap<String, Object>();
					map.put("memberId", member.getId());
					map.put("owner","keep");
					List<MemberHas> keepList=memberBiz.getHasList(map);
					//拍卖
					Map<String, Object> mapLove = new HashMap<String, Object>();
					mapLove.put("memberId", member.getId());
					mapLove.put("owner","love");
					List<MemberHas> loveList=memberBiz.getHasList(mapLove);
					//look love keep 
					//发现、拍卖、展览馆
					Map<String, Object> mapLook = new HashMap<String, Object>();
					mapLook.put("memberId", member.getId());
					mapLook.put("owner","look");
					List<MemberHas> lookList=memberBiz.getHasList(mapLook);
					request.setAttribute("member", member);
					request.setAttribute("keepList", keepList);
					request.setAttribute("loveList", loveList);
					request.setAttribute("lookList", lookList);
					//艺术家的关注
					//like
					Map<String, Object> mapLike = new HashMap<String, Object>();
					mapLike.put("memberId", member.getId());
					mapLike.put("owner","like");
					List<MemberHas> likeList=memberBiz.getHasList(mapLike);
					if(likeList.size()>0){
					for(MemberHas memberHas :likeList){
						ArtArtist artist =artMadeBiz.getArtist(memberHas.getOwnerId());
						memberHas.setArtArtist(artist);
						ArtArtist allCount=artFindBiz.getAllCountByArtistId(artist.getId());
						if(allCount!=null){
							artist.setViewAmount(allCount.getViewAmount());
							artist.setLoveAmount(allCount.getLoveAmount());
						}
					}
					}
					request.setAttribute("likeList", likeList);
				} catch (AppBusinessException e) {
					e.printStackTrace();
				}
				return "artOne/member/mKeep";
			} else {
				response.sendRedirect("/welcome.htm");
				return null;
			}

		}
	    //冲保证金
		@RequestMapping(value = "/mPay.htm")
		public String mPay(HttpServletRequest request, HttpServletResponse response) throws IOException {
			OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser");
			if (onLineUserListener != null) {
				try {
					Member member = memberBiz.getMemberById(onLineUserListener.getMember().getId());
					request.setAttribute("member", member);
				} catch (AppBusinessException e) {
					e.printStackTrace();
				}
				return "artOne/member/mpayMoney";
			} else {
				response.sendRedirect("/welcome.htm");
				return null;
			}

		}
		//保存喜好
		@RequestMapping(value = "/saveHobby.htm")
		public void saveHobby(String doingList,HttpServletRequest request,HttpServletResponse response) throws AppBusinessException {
			try {
				response.setContentType("text/html; charset=UTF-8");
				PrintWriter out = response.getWriter(); 
				OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser"); 
				Member m = onLineUserListener.getMember();
				if (m!=null){
						memberBiz.deleteMemberHobby(m.getId());
					JSONArray doingArray = JSONArray.fromObject( doingList);
						for (Object object : doingArray) {
			                MemberHobby memberHobby = new MemberHobby();
							memberHobby.setMemberId(m.getId());
							memberHobby.setHobbyId((String)object);
							memberBiz.insertMemberHobby(memberHobby);
		                } 
					out.print("success");
					} else {
						out.print("error");
					}
			} catch (Exception e) {
				e.printStackTrace();
			}

		}
		@RequestMapping(value = "/mComment.htm")
		public String mComment(Integer page,HttpServletRequest request, HttpServletResponse response) throws IOException {
			OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser");
			if (page == null) {
				page = 1;
			}
			if (onLineUserListener != null) {
				try {
					PageModel  model  =artFindBiz.getFindCommentModelByMemberId(page,onLineUserListener.getMember().getId());
					request.setAttribute("model", model);
				} catch (AppBusinessException e) {
					e.printStackTrace();
				}
				return "artOne/member/mComment";
			} else {
				response.sendRedirect("/welcome.htm");
				return null;
			}
		}
		//删除评论
		@RequestMapping(value = "/deleteComment.htm")
		public void deleteComment(String doingList,HttpServletRequest request,HttpServletResponse response) throws AppBusinessException {
			try {
				response.setContentType("text/html; charset=UTF-8");
				PrintWriter out = response.getWriter(); 
				OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser"); 
				Member m = onLineUserListener.getMember();
				if (m!=null){
						JSONArray doingArray = JSONArray.fromObject( doingList);
						for (Object object : doingArray) {
							memberBiz.deleteComment((String)object);
		                } 
					out.print("success");
					} else {
						out.print("error");
					}
			} catch (Exception e) {
				e.printStackTrace();
			}

		}
		//新浪微博登录
	    /*@RequestMapping(value = "/member/sinalogin.htm")
	    public void sinaLogin(HttpServletResponse response, String historyUrl) {
	        try {
	            //String rel = weiboBiz.requestOauthSina(historyUrl);
	            //response.sendRedirect(rel);
	        } catch (Exception e) {
	            logger.error("[/member/sinalogin.htm] fail", e);
	            e.printStackTrace();
	        }
	    }*/
		//提取保证金
		@RequestMapping(value = "/returnMoney.htm")
		public String returnMoney(HttpServletRequest request, HttpServletResponse response) throws IOException {
			OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser");
			
			if (onLineUserListener != null) {
				
				try {
					Member member = memberBiz.getMemberById(onLineUserListener.getMember().getId());
					request.setAttribute("member", member);
				} catch (AppBusinessException e) {
					e.printStackTrace();
				}
				
				return "artOne/member/returnMoney";
			} else {
				response.sendRedirect("/welcome.htm");
				return null;
			}
		}
		//新增保证金
		@RequestMapping(value = "/insertMemberSecurity.htm")
		public void deleteComment(MemberSecurity memberSecurity,HttpServletRequest request,HttpServletResponse response) throws AppBusinessException {
			try {
				response.setContentType("text/html; charset=UTF-8");
				PrintWriter out = response.getWriter(); 
				OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser"); 
				Member m = onLineUserListener.getMember();
				if (m!=null){
						memberSecurity.setMemberId(m.getId());
						memberSecurity.setType("02");//02提现
						memberBiz.insertMemberSecurity(memberSecurity);
						out.print("success");
					} else {
						out.print("error");
					}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		//新增充值
		@RequestMapping(value = "/insertMemberPay.htm")
		public void insertMemberPay(MemberSecurity memberSecurity,HttpServletRequest request,HttpServletResponse response) throws AppBusinessException {
			try {
				response.setContentType("text/html; charset=UTF-8");
				OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser"); 
				Member m = onLineUserListener.getMember();
				if (m!=null){
						memberSecurity.setMemberId(m.getId());
						memberSecurity.setType("01");//充值
						String id =memberBiz.insertMemberPay(memberSecurity);
						response.setContentType("text/html; charset=UTF-8");
						PrintWriter pw = null;
						pw = response.getWriter();
						ArtPic artPicNull = new ArtPic();
						artPicNull.setError("succus");
						artPicNull.setIdentifier(id);
						pw = response.getWriter();
						pw.print(JSONObject.fromObject(artPicNull));
					} else {
						response.sendRedirect("/member.htm");
					}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		//新浪微博登录
	    @RequestMapping(value = "/sinalogin.htm", method = RequestMethod.POST)
	    public void sinaLogin(String sinaId,String sinaName,HttpServletRequest request, HttpServletResponse response) throws AppBusinessException {
	        try {
	        	Member m = memberBiz.getMemberNickName(sinaName+"_sina");
	        	if(m!=null && !"".equals(m.getPassword())){
	        		PrintWriter out = response.getWriter();
		            response.setContentType("text/html;charset=UTF-8");
	        		request.getSession(true).setAttribute("onlineUser", new OnLineUserListener(m));
	        		request.getSession(true).setAttribute("out","sina");
	        		//response.sendRedirect("/member.htm");
	        		out.print("false");
	        	}else{
	        		PrintWriter out = response.getWriter();
		            response.setContentType("text/html;charset=UTF-8");
		            request.getSession(true).setAttribute("outName", sinaName+"_sina");
		            request.getSession(true).setAttribute("outId", sinaId+"_sina");
		    		out.print("true");
	        	}
	        	System.out.println(sinaId+"___________________________________________________________________________"+sinaName);
	        	
	        } catch (Exception e) {
	            logger.error("[/member/sinalogin.htm] fail", e);
	            e.printStackTrace();
	        }
	    }
	  //QQ登录
	    @RequestMapping(value = "/qqlogin.htm", method = RequestMethod.POST)
	    public String qqlogin(String qqfigureurl,String qqName,HttpServletRequest request, HttpServletResponse response) throws AppBusinessException {
	        try {
	        	Member m = memberBiz.getMemberNickName(qqName+"_qq");
	        	if(m!=null && !"".equals(m.getPassword())){
	        		PrintWriter out = response.getWriter();
		            response.setContentType("text/html;charset=UTF-8");
	        		request.getSession(true).setAttribute("onlineUser", new OnLineUserListener(m));
	        		request.getSession(true).setAttribute("out","qq");
	        		//response.sendRedirect("/member.htm");
	        		out.print("false");
	        	}else{
	        		PrintWriter out = response.getWriter();
		            response.setContentType("text/html;charset=UTF-8");
	        		request.getSession(true).setAttribute("outName", qqName+"_qq");
	        		request.getSession(true).setAttribute("qqfigureurl", qqfigureurl);
	        		out.print("true");
	        		/*PrintWriter out = response.getWriter();
		            response.setContentType("text/html;charset=UTF-8");
	        		Member member =new Member();
	        		member.setNickname(qqName);
	        		member.setAvatar(qqfigureurl);
	        		Member memeberSession = memberBiz.register("", member);
					request.getSession(true).setAttribute("onlineUser",
							new OnLineUserListener(memeberSession));
					out.print("true");*/
	        		
	        	}
	        	System.out.println(qqfigureurl+"___________________________________________________________________________"+qqName);
	        } catch (Exception e) {
	            logger.error("[/member/sinalogin.htm] fail", e);
	            e.printStackTrace();
	        }
	        return null;
	    }
	    @RequestMapping(value = "/outRegister.htm")
		public String outRegister(HttpServletRequest request, HttpServletResponse response) throws IOException {
			return "artOne/member/outRegister";
		}
	    //退货
	    @RequestMapping(value = " /insertArtBack.htm")
		public void  insertArtBack(ArtBack artBack,HttpServletRequest request,HttpServletResponse response) throws AppBusinessException {
			try {
				response.setContentType("text/html; charset=UTF-8");
				OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser"); 
				Member m = onLineUserListener.getMember();
				if (m!=null){
						artBack.setMemberId(m.getId());
						artBack.setStatus("01");//未审核，同意，拒绝
						memberBiz.insertArtBack(artBack);
						response.setContentType("text/html; charset=UTF-8");
						PrintWriter pw = null;
						pw = response.getWriter();
						pw = response.getWriter();
						ArtPic artPicNull = new ArtPic();
						artPicNull.setError("succuss");
						artPicNull.setIdentifier(artBack.getBackId());
						pw = response.getWriter();
						pw.print(JSONObject.fromObject(artPicNull));
					} else {
						response.sendRedirect("/member.htm");
					}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	    
	    //申请退货
	    @RequestMapping(value = " /toBack.htm")
		public void  toBack(String id,HttpServletRequest request,HttpServletResponse response) throws AppBusinessException {
			try {
				response.setContentType("text/html; charset=UTF-8");
				OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser"); 
				Member m = onLineUserListener.getMember();
				if (m!=null){
						memberBiz.insertBackLog(id,m.getId());
						response.setContentType("text/html; charset=UTF-8");
						PrintWriter pw = null;
						pw = response.getWriter();
						pw = response.getWriter();
						pw.print("success");
					} else {
						response.sendRedirect("/member.htm");
					}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	    //退货log列表页面
	    @RequestMapping(value = "/mBackLog.htm")
		public String toBackLog(String id,HttpServletRequest request, HttpServletResponse response) throws IOException {
			OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser");
		
			if (onLineUserListener != null) {
				try {
					//日志
					List<ArtProcessLog> logs =memberBiz.getProcessList(id);
					//订单详情
					ArtOrders artOrder =memberBiz.getOrdersById(id);
					if(artOrder!=null){
						//拒绝Common.BACK_REFUSAL
						if("02".equals(artOrder.getBackStatus())){
							ArtProcessLog refusalLog =memberBiz.getArtProcessLogByRef(id,Common.BACK_REFUSAL); 
							request.setAttribute("refusalLog", refusalLog);
						}
					}
					ArtBack artBack =memberBiz.getArtBackByOid(id);
					request.setAttribute("artBack", artBack);
					request.setAttribute("logs", logs);
					request.setAttribute("artOrder", artOrder);
				} catch (AppBusinessException e) {
					e.printStackTrace();
				}
				return "artOne/member/mBackLog";
			} else {
				response.sendRedirect("/welcome.htm");
				return null;
			}
		}
	   
}

	